package io.gitee.zicai.bus.sample.adaptor;

import io.gitee.zicai.bus.adaptor.BaseBusSendAdaptor;
import io.gitee.zicai.bus.sample.cmd.CmdSendParam;
import io.gitee.zicai.bus.sample.cmd.ICmdSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * CmdSendAdaptor
 *
 * @author zicai
 * @since 2021-04-02
 */
@Slf4j
@Component
public class CmdSendAdaptor extends BaseBusSendAdaptor<ICmdSender, CmdSendBus, CmdSendParam> {

    @Autowired
    private ICmdSender cmdSender;

    /**
     * 厂商的命令发送服务
     *
     * @param brandName 厂商名称
     * @return IBusSender
     */
    @Override
    public ICmdSender getCmdSender(String brandName) {
        return cmdSender;
    }

    public void send(CmdSendParam sendParam) {
        bus.publish(CmdSendBus.of(sendParam));
    }

    @Override
    public void onException(CmdSendBus bus, Exception e) {
        log.error(">>> ");
    }
}
